using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Data;

using TSFileOutput.Data;

namespace TSFileOutput.Core
{
    public class ProjectManager : IDisposable
    {
        private string errmsg = string.Empty;

        public string ErrMsg
        {
            get { return errmsg; }
            set { errmsg = value; }
        }

        public ProjectManager()
        {
        }

        #region GetAllCompany
        public TSProjectManagers GetPMs()
        {
            TSProjectManagers ResultObj = null;

            DataSet dsPMs = SqlHelper.ExecuteDataSet(TSFileOutput.Data.Data.ConnectionString, CommandType.Text, " select UserId, UserName, Email from vw_aspnet_MembershipUsers  where UserId in (select UserId from tbl_ProjectManager) ");
            DataTable ResultTable = dsPMs.Tables[0];

            if (ResultTable != null)
            {
                ResultObj = new TSProjectManagers();

                foreach (DataRow ResultRow in ResultTable.Rows)
                {
                    TSProjectManager ResultPM = this.LoadPM(ResultRow);
                    ResultObj.Add(ResultPM);
                }
            }

            return ResultObj;
        }
        #endregion

        #region Protected

        #region LoadPM
        protected TSProjectManager LoadPM(DataRow ResultRow)
        {
            TSProjectManager ResultObj = null;

            if (ResultRow != null)
            {
                ResultObj = new TSProjectManager(
                    ResultRow["UserId"].ToString(),
                    ResultRow["UserName"].ToString(),
                    ResultRow["Email"].ToString());
            }
            else
            {
                this.ErrMsg = "[TSProjectManager.FillData] : ResultRow is null";
            }

            return ResultObj;
        }
        #endregion

        #endregion

        public void Dispose()
        {
            //Dispose(true);
        }
    }

    public class TSProjectManager
    {
        private string id = string.Empty;
        private string name = string.Empty;
        private string email = string.Empty;

        public string ID
        {
            get { return id; }
        }

        public string Name
        {
            get { return name; }
        }

        public string Email
        {
            get { return email; }
        }


        public TSProjectManager(string id, string name, string email)
        {
            this.id = id;
            this.name = name;
            this.email = email;
        }
    }

    public class TSProjectManagers : CollectionBase
    {
        public TSProjectManager this[int index]
        {
            get { return ((TSProjectManager)List[index]); }
            set { List[index] = value; }
        }

        public int Add(TSProjectManager value)
        {
            return (List.Add(value));
        }

        public int IndexOf(TSProjectManager value)
        {
            return (List.IndexOf(value));
        }

        public void Insert(int index, TSProjectManager value)
        {
            List.Insert(index, value);
        }

        public void Remove(TSProjectManager value)
        {
            List.Remove(value);
        }

        public bool Contains(TSProjectManager value)
        {
            // If value is not of type Int16, this will return false.
            return (List.Contains(value));
        }
    }
}
